package org.exia.minisig.services;

import java.util.ArrayList;

import org.exia.minisig.model.dao.NewsDAO;
import org.exia.minisig.model.object.News;

public class NewsManager {
	//CONSTRUCTOR
	public NewsManager() {
		initializeVar();
	}
	public void initializeVar(){
		
	}
	//METHODE
	public ArrayList<News> getAll(){
		NewsDAO newsDAO = new NewsDAO();
		ArrayList<News> listNews = new ArrayList<>();
		for (Object newObject : newsDAO.getList()) {
			listNews.add((News)newObject);
		}
		return listNews;
	}
	public void addNews(News _new){
		NewsDAO news = new NewsDAO(_new);
		news.add();				 
		  news.setID();
		  //2- Ajout des image
		  news.linkImages();
		  //3-Ajout URL
		  news.linkURL();
	}
	public void removeNews(News _news){
		NewsDAO news = new NewsDAO(_news);
		news.deleteImg();
		news.deleteUrl();
		news.delete();
	}
	public void updateNews(News _news){
		 NewsDAO news = new NewsDAO(_news);
		 //1. Supression des URL + IMG
		 news.deleteUrl();
		 news.deleteImg();
		 //2. Update
		 news.update();
		 //3.relier Image
		 news.linkImages();
		 news.linkURL();
	}
}
